#include "ImpliedVolBisection.h"


//Computes an implied volatility for each option that we have data for

double FindImpliedVol(int type, double underly_price, double strike_price, 
double time_in_days, double risk_free, double div_yield, double opt_price)
{
 
 double volguesshigh = 3;
 double volguesslow = .00001;
 double volguess = 0;
 double price_estimate = 0;
 int i=0;

for(i=0; i<30; i++)
{
       volguess = (volguesshigh+volguesslow)/2;
       price_estimate = ModelBlackScholes(type, underly_price, strike_price, volguess, time_in_days, risk_free, div_yield);
       
       if (price_estimate > opt_price)
       {
          volguesshigh = volguess;
       }
       else
       {
          volguesslow = volguess;    
       }
}
return (volguess);
}
